/**
 * 回文判断
 * 【示例】fn("abcba") = true
 */

// 1.借助数组的反转数组方法
const checkPalindromeOne = (str) => {
    return str === str.split("").reverse().join("")
}

console.log(checkPalindromeOne("abcba"))

// 2.不借助数组。利用循环创建新字符串
const checkPalindromeTwo = (str) => {
    let newStr = ""
    for (let i = 0; i < str.length; i += 1) {
        newStr += str[i]
    }
    return newStr === str
}
console.log(checkPalindromeTwo("abcba"))

// 3.不创建新字符串 比较对应位置的字符
const checkPalindromeThree = (str) => {
    const length = str.length
    for (let i = 0; i < Math.floor(length / 2); i += 1) {
        if (str[i] !== str[length - 1 - i]) {
            return false
        }
    }
    return true
}
console.log(checkPalindromeThree("abcba"))
